<template>
    <view class="content">
		<view class="iptop">
			<view class="txcon">
				<image :src="pic?imgoss+pic:'/static/mrimg.png'" mode="aspectFill" class="logo"></image>
				<view class="txt" @tap="chooseimage"><image src="/static/pzrq.png" mode="widthFix"></image></view>
			</view>
			<view class="txt1">ID:{{user.id}}</view>
			<view class="nrcon">
				<view class="txt2">姓名</view>
				<input class="txt3" type="text" v-model="name" placeholder="请输入姓名" />
			</view>
			<view class="nrcon" style="border-bottom: none;" @tap="datebtn">
				<view class="txt2">生日</view>
				<view>{{birthday?birthday:'请选择生日'}}</view>
			</view>
		</view>
		<view class="btn" @tap="save">
			保存
		</view>
		<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
    </view>
</template>

<script>
const app = getApp();
var util = require('../../utils/util.js');
var encrypt = require('../../utils/api.js');
export default {
    data() {
        return {
			img_src: app.globalData.img_src,
			img_url: app.globalData.img_urls,
			imgoss: app.globalData.imgoss,
			array: ['请选择性别', '男', '女'],
			index: 0,
			params: {
				year: true,
				month: true,
				day: true,
				hour: false,
				minute: false,
				second: false,
				// 选择时间的时间戳
				timestamp: true,
			},
			show: false,
			birthday:'',
			pic:'',
			name:'',
			pwd:'',
			mobile:'',
			user:''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        var that = this;
		this.Getuser()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
		
		Getuser() {
			var that = this;
			app.globalData.api.request('User/my', {}, "POST", 'form').then(res => {
				if (res.code == 0) {
					//console.log(res)
					this.user = res.data.user
					this.pic = res.data.user.pic?res.data.user.pic:'';
					this.name = res.data.user.name?res.data.user.name:'';
					this.birthday = res.data.user.birthday?res.data.user.birthday:'';
				} else {
					return app.globalData.show(res.msg);
				}
			})
		},
		save(){
			var that = this;
			if (this.pic == '') {
				app.globalData.show('请点击上传头像~')
				return true
			}
			if (this.name == '') {
				app.globalData.show('请输入姓名~')
				return true
			}
			app.globalData.api.request('User/updateUser', {
				pic:this.pic,
				name:this.name,
				birthday:this.birthday,
			}, "POST", 'form').then(res => {
				//console.log(res)
				if (res.code == 0) {
					app.globalData.d('修改成功~')
				} else {
					return app.globalData.show(res.msg);
				}
			})
		},
		chooseimage(){
		  var that = this
		  var url = this.img_url+'api/upload/uploadpic'
		  util.chooseimage(url,'',function(res){
		    var data = res.data;
		    //console.log(data)
		    // data = encrypt.decryptAES(data.list,data.str)
		    that.pic = data
		  })
		  
		},
		confirm(e){
			//console.log(e)
			this.birthday = e.year+'-'+e.month+'-'+e.day
		},
		datebtn(){
			//console.log(123)
			this.show = true
		},
		bindPickerChange: function(e) {
			//console.log('picker发送选择改变，携带值为', e.detail.value)
			this.index = e.detail.value
		},
	}
};
</script>
<style>
	.btns{
		width: 686rpx;
		height: 85rpx;
		border-radius: 50px;
		text-align: center;
		line-height: 85rpx;
		margin:0rpx 32rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #000000;
		margin-bottom: 80rpx;
	}
	.btn{
		width: 686rpx;
		height: 85rpx;
		border-radius: 50px;
		background-color: #8665AF;
		text-align: center;
		line-height: 85rpx;
		margin:80rpx 32rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #fff;
		margin-bottom: 0px;
	}
	.uni-input{
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
		width: 100%;
		height: auto;
		line-height: 100rpx;
		position: relative;
	}
	.txt4{
		width: 80%;
		height: 100rpx;
		display: table;
		float: left;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
	}
	.txt2{
		width: 20%;
		height: 100rpx;
		display: table;
		float: left;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #999999;
		line-height: 100rpx;
	}
	.txt3{
		width: 80%;
		height: 100rpx;
		display: table;
		float: left;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
	}
	.nrcon{
		width: 686rpx;
		height: 100rpx;
		display: table;
		margin-left: 32rpx;
		border-bottom: 1px solid #D8D8D8;
	}
	.nrcon>view:nth-child(2){
		height: 100rpx;
		display: table;
		float: left;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 28rpx;
		color: #222;
		line-height: 100rpx;
	}
	.txt1{
		width: 100%;
		height: auto;
		display: table;
		text-align: center;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
		margin: 10rpx 0px;
		margin-bottom: 50rpx;
	}
	.txt>image{
		width: 22px;
		height: auto;
		display: table;
		margin:4px auto;
	}
	.txt{
		width: 100%;
		height: auto;
		display: table;
		background-color: rgba(0, 0, 0, 0.6);
		position: absolute;
		left: 0px;
		bottom:0px;
	}
	.logo{
		width: 200rpx;
		height: 200rpx;
		display: table;
		margin: auto;
		border-radius: 200rpx;
	}
	.txcon{
		width: 200rpx;
		height: 200rpx;
		display: table;
		margin: auto;
		border-radius: 200rpx;
		position: relative;
		overflow: hidden;
		margin-top: 100rpx;
	}
	.iptop{
		width: 100%;
		height: auto;
		display: table;
		background-color: #fff;
	}
	page{
		background-color: #f6f6f6;
	}
	.content {
		width: 100%;
		height: auto;
		display: table;
		box-sizing: border-box;
	}
</style>
